﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.ZhaoLuService;
using org.in2bits.MyXls;

namespace CommunitySystem.PageView
{
    public partial class ZhaoLu_DaoRuKaoShengControl_FQ : UserControl
    {
        private ZhaoLuService.ZhaoLuServiceClient Client1 = new ZhaoLuServiceClient();
        private ObservableCollection<ZhaoLu_DaoRuKaoShengModel> Source =
            new ObservableCollection<ZhaoLu_DaoRuKaoShengModel>();
        public ZhaoLu_DaoRuKaoShengControl_FQ()
        {
            InitializeComponent();
            for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            {
                ComboBoxItem cbi = new ComboBoxItem();
                cbi.Content = i.ToString();
                cbi.Tag = i;
                nian.Items.Add(cbi);
            }
            nian.SelectedIndex = 0;
            Client1.GetZhaoLu_DaoRuKaoShengModelCompleted += new EventHandler<GetZhaoLu_DaoRuKaoShengModelCompletedEventArgs>(Client1_GetZhaoLu_DaoRuKaoShengModelCompleted);
            Load();
        }
        private void Load()
        {
            Client1.GetZhaoLu_DaoRuKaoShengModelAsync(DateTime.Today.Year - nian.SelectedIndex, true,yue.SelectedIndex + 1,0);
        }
        void Client1_GetZhaoLu_DaoRuKaoShengModelCompleted(object sender, GetZhaoLu_DaoRuKaoShengModelCompletedEventArgs e)
        {
            Source = e.Result;
            DGRole.ItemsSource = e.Result;
        }

        private ObservableCollection<ZhaoLu_DaoRuKaoShengModel> selectedempmodel =
            new ObservableCollection<ZhaoLu_DaoRuKaoShengModel>();
        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            foreach (ZhaoLu_DaoRuKaoShengModel p in DGRole.ItemsSource)
            {
                p.IsSelected = (bool)cb.IsChecked;
                if (p.IsSelected)
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(p);
                    }
                }
                else
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() != null)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault());
                    }
                }
            }

        }
        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Load();
        }
        private Stream ss = null;
        private void btnOut_Click(object sender, RoutedEventArgs e)
        {
            if (Source != null && Source.Count > 0)
            {
                var downLoad = new SaveFileDialog()
                {
                    //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
                    Filter = "Excel files(2003) (*.xls)|*.xls",
                };
                if (downLoad.ShowDialog() == true)
                {
                    ss = downLoad.OpenFile();
                    PageInit();
                }
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("没有要导出的数据！");
            
        }
        public void PageInit()
        {
            XlsDocument xls = new XlsDocument();
            XF xf = xls.NewXF();
            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment = VerticalAlignments.Centered;
            xf.UseBorder = true;
            xf.TopLineStyle = 1;
            xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf.BottomLineStyle = 1;
            xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf.LeftLineStyle = 1;
            xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf.RightLineStyle = 1;
            xf.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf.TextWrapRight = true;

            XF xf1 = xls.NewXF();
            xf1.UseBorder = true;
            xf1.TopLineStyle = 1;
            xf1.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.BottomLineStyle = 1;
            xf1.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.LeftLineStyle = 1;
            xf1.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.RightLineStyle = 1;
            xf1.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.HorizontalAlignment = HorizontalAlignments.Centered;
            xf1.VerticalAlignment = VerticalAlignments.Centered;
            xf1.Font.Bold = true;
            xf1.Font.Height = 15 * 20;

            XF xf3 = xls.NewXF();
            xf3.UseBorder = true;
            xf3.TopLineStyle = 1;
            xf3.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.BottomLineStyle = 1;
            xf3.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.LeftLineStyle = 1;
            xf3.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.RightLineStyle = 1;
            xf3.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.HorizontalAlignment = HorizontalAlignments.Centered;
            xf3.VerticalAlignment = VerticalAlignments.Centered;
            xf3.Font.Bold = true;
            xf3.Font.Height = 12 * 20;

            Worksheet sheet1 = xls.Workbook.Worksheets.AddNamed("人员放弃名单");
            sheet1.Cells.Merge(1, 1, 1, 52);
            sheet1.Cells.Add(1, 1, "徐汇区" + (DateTime.Today.Year - nian.SelectedIndex).ToString() + "年招录人员放弃名单", xf1);
            sheet1.Cells.Add(2, 1, "序号", xf3);
            sheet1.Cells.Add(2, 2, "注册编号", xf3);
            sheet1.Cells.Add(2, 3, "姓名", xf3);
            sheet1.Cells.Add(2, 4, "身份证号", xf3);
            sheet1.Cells.Add(2, 5, "职位ID", xf3);
            sheet1.Cells.Add(2, 6, "招录单位", xf3);
            sheet1.Cells.Add(2, 7, "用人部门", xf3);
            sheet1.Cells.Add(2, 8, "报考职位", xf3);
            sheet1.Cells.Add(2, 9, "招考科目", xf3);
            sheet1.Cells.Add(2, 10, "申论", xf3);

            sheet1.Cells.Add(2, 11, "行测", xf3);
            sheet1.Cells.Add(2, 12, "政法", xf3);
            sheet1.Cells.Add(2, 13, "总分", xf3);
            sheet1.Cells.Add(2, 14, "性别", xf3);
            sheet1.Cells.Add(2, 15, "出生日期", xf3);
            sheet1.Cells.Add(2, 16, "健康程度", xf3);
            sheet1.Cells.Add(2, 17, "身高", xf3);
            sheet1.Cells.Add(2, 18, "体重", xf3);
            sheet1.Cells.Add(2, 19, "民族", xf3);
            sheet1.Cells.Add(2, 20, "婚姻状况", xf3);

            sheet1.Cells.Add(2, 21, "配偶学历", xf3);
            //sheet1.Cells.Add(2, 22, "注册编号", xf3);
            sheet1.Cells.Add(2, 22, "考生身份", xf3);
            sheet1.Cells.Add(2, 23, "学历", xf3);
            sheet1.Cells.Add(2, 24, "政治面貌", xf3);
            sheet1.Cells.Add(2, 25, "学位", xf3);
            sheet1.Cells.Add(2, 26, "本科毕业院校", xf3);
            sheet1.Cells.Add(2, 27, "本科专业", xf3);
            sheet1.Cells.Add(2, 28, "本科毕业时间", xf3);
            sheet1.Cells.Add(2, 29, "硕士毕业院校", xf3);

            sheet1.Cells.Add(2, 30, "硕士专业", xf3);
            sheet1.Cells.Add(2, 31, "硕士毕业时间", xf3);
            sheet1.Cells.Add(2, 32, "博士毕业院校", xf3);
            sheet1.Cells.Add(2, 33, "博士专业", xf3);
            sheet1.Cells.Add(2, 34, "博士毕业时间", xf3);
            sheet1.Cells.Add(2, 35, "个人简历", xf3);
            sheet1.Cells.Add(2, 36, "特长获职业证书", xf3);
            sheet1.Cells.Add(2, 37, "所学主要课程", xf3);
            sheet1.Cells.Add(2, 38, "外语1", xf3);
            sheet1.Cells.Add(2, 39, "外语2", xf3);

            sheet1.Cells.Add(2, 40, "外语等级1", xf3);
            sheet1.Cells.Add(2, 41, "外语等级2", xf3);
            sheet1.Cells.Add(2, 42, "计算机水平", xf3);
            sheet1.Cells.Add(2, 43, "通讯地址", xf3);
            sheet1.Cells.Add(2, 44, "联系方式", xf3);
            sheet1.Cells.Add(2, 45, "手机号码", xf3);
            sheet1.Cells.Add(2, 46, "工作单位", xf3);
            sheet1.Cells.Add(2, 47, "工作年限", xf3);
            sheet1.Cells.Add(2, 48, "毕业生界别", xf3);
            sheet1.Cells.Add(2, 49, "生源", xf3);

            sheet1.Cells.Add(2, 50, "户籍", xf3);
            sheet1.Cells.Add(2, 51, "邮编", xf3);
            sheet1.Cells.Add(2, 52, "放弃环节", xf3);

            ColumnInfo colInfoxueli1 = new ColumnInfo(xls, sheet1);
            colInfoxueli1.Width = 40 * 256;
            colInfoxueli1.ColumnIndexStart = 6;
            colInfoxueli1.ColumnIndexEnd = 6;
            sheet1.AddColumnInfo(colInfoxueli1);

            ColumnInfo colInfoxueli2 = new ColumnInfo(xls, sheet1);
            colInfoxueli2.Width = 15 * 256;
            colInfoxueli2.ColumnIndexStart = 26;
            colInfoxueli2.ColumnIndexEnd = 26;
            sheet1.AddColumnInfo(colInfoxueli2);

            ColumnInfo colInfoxueli3 = new ColumnInfo(xls, sheet1);
            colInfoxueli3.Width = 15 * 256;
            colInfoxueli3.ColumnIndexStart = 29;
            colInfoxueli3.ColumnIndexEnd = 29;
            sheet1.AddColumnInfo(colInfoxueli3);

            ColumnInfo colInfoxueli4 = new ColumnInfo(xls, sheet1);
            colInfoxueli4.Width = 15 * 256;
            colInfoxueli4.ColumnIndexStart = 32;
            colInfoxueli4.ColumnIndexEnd = 32;
            sheet1.AddColumnInfo(colInfoxueli4);

            ColumnInfo colInfoxueli5 = new ColumnInfo(xls, sheet1);
            colInfoxueli5.Width = 30 * 256;
            colInfoxueli5.ColumnIndexStart = 35;
            colInfoxueli5.ColumnIndexEnd = 35;
            sheet1.AddColumnInfo(colInfoxueli5);
            ColumnInfo colInfoxueli6 = new ColumnInfo(xls, sheet1);
            colInfoxueli6.Width = 30 * 256;
            colInfoxueli6.ColumnIndexStart = 36;
            colInfoxueli6.ColumnIndexEnd = 36;
            sheet1.AddColumnInfo(colInfoxueli6);

            ColumnInfo colInfoxueli7 = new ColumnInfo(xls, sheet1);
            colInfoxueli7.Width = 30 * 256;
            colInfoxueli7.ColumnIndexStart = 37;
            colInfoxueli7.ColumnIndexEnd = 37;
            sheet1.AddColumnInfo(colInfoxueli7);

            ColumnInfo colInfoxueli8 = new ColumnInfo(xls, sheet1);
            colInfoxueli8.Width = 25 * 256;
            colInfoxueli8.ColumnIndexStart = 43;
            colInfoxueli8.ColumnIndexEnd = 43;
            sheet1.AddColumnInfo(colInfoxueli8);

            
                for (int i = 0; i < Source.Count; i++)
                {
                    sheet1.Cells.Add(i + 3, 1, i + 1, xf);
                    if (Source[i].ZCBH != null) sheet1.Cells.Add(i + 3, 2, Source[i].ZCBH.ToString(), xf);
                    if (Source[i].XingMing != null) sheet1.Cells.Add(i + 3, 3, Source[i].XingMing.ToString(), xf);
                    if (Source[i].SFZH != null) sheet1.Cells.Add(i + 3, 4, Source[i].SFZH.ToString(), xf);
                    if (Source[i].ZWID != null) sheet1.Cells.Add(i + 3, 5, Source[i].ZWID.ToString(), xf);
                    if (Source[i].ZLDW != null) sheet1.Cells.Add(i + 3, 6, Source[i].ZLDW.ToString(), xf);
                    if (Source[i].YRBM != null) sheet1.Cells.Add(i + 3, 7, Source[i].YRBM.ToString(), xf);
                    if (Source[i].BBZW != null) sheet1.Cells.Add(i + 3, 8, Source[i].BBZW.ToString(), xf);
                    if (Source[i].ZKKM != null) sheet1.Cells.Add(i + 3, 9, Source[i].ZKKM.ToString(), xf);
                    if (Source[i].SL != null) sheet1.Cells.Add(i + 3, 10, Source[i].SL.ToString(), xf);

                    if (Source[i].XC != null) sheet1.Cells.Add(i + 3, 11, Source[i].XC.ToString(), xf);
                    if (Source[i].ZF != null) sheet1.Cells.Add(i + 3, 12, Source[i].ZF.ToString(), xf);
                    if (Source[i].ZongFen != null) sheet1.Cells.Add(i + 3, 13, Source[i].ZongFen.ToString(), xf);
                    if (Source[i].XB != null) sheet1.Cells.Add(i + 3, 14, Source[i].XB.ToString(), xf);
                    if (Source[i].CSRQ != null) sheet1.Cells.Add(i + 3, 15, Source[i].CSRQ.ToString(), xf);
                    if (Source[i].JKCD != null) sheet1.Cells.Add(i + 3, 16, Source[i].JKCD.ToString(), xf);
                    if (Source[i].SG != null) sheet1.Cells.Add(i + 3, 17, Source[i].SG.ToString(), xf);
                    if (Source[i].TZ != null) sheet1.Cells.Add(i + 3, 18, Source[i].TZ.ToString(), xf);
                    if (Source[i].MZ != null) sheet1.Cells.Add(i + 3, 19, Source[i].MZ.ToString(), xf);
                    if (Source[i].HYZK != null) sheet1.Cells.Add(i + 3, 20, Source[i].HYZK.ToString(), xf);

                    if (Source[i].POXL != null) sheet1.Cells.Add(i + 3, 21, Source[i].POXL.ToString(), xf);
                    if (Source[i].KSSF != null) sheet1.Cells.Add(i + 3, 22, Source[i].KSSF.ToString(), xf);
                    if (Source[i].XL != null) sheet1.Cells.Add(i + 3, 23, Source[i].XL.ToString(), xf);
                    if (Source[i].ZZMM != null) sheet1.Cells.Add(i + 3, 24, Source[i].ZZMM.ToString(), xf);
                    if (Source[i].XW != null) sheet1.Cells.Add(i + 3, 25, Source[i].XW.ToString(), xf);
                    if (Source[i].BKBYYX != null) sheet1.Cells.Add(i + 3, 26, Source[i].BKBYYX.ToString(), xf);
                    if (Source[i].BKZY != null) sheet1.Cells.Add(i + 3, 27, Source[i].BKZY.ToString(), xf);
                    if (Source[i].BKBYSJ != null) sheet1.Cells.Add(i + 3, 28, Source[i].BKBYSJ.ToString(), xf);
                    if (Source[i].SSYX != null) sheet1.Cells.Add(i + 3, 29, Source[i].SSYX.ToString(), xf);
                    if (Source[i].SSZY != null) sheet1.Cells.Add(i + 3, 30, Source[i].SSZY.ToString(), xf);

                    if (Source[i].SSBYSJ != null) sheet1.Cells.Add(i + 3, 31, Source[i].SSBYSJ.ToString(), xf);
                    if (Source[i].BSYX != null) sheet1.Cells.Add(i + 3, 32, Source[i].BSYX.ToString(), xf);
                    if (Source[i].BSZY != null) sheet1.Cells.Add(i + 3, 33, Source[i].BSZY.ToString(), xf);
                    if (Source[i].BSBYSJ != null) sheet1.Cells.Add(i + 3, 34, Source[i].BSBYSJ.ToString(), xf);
                    if (Source[i].GRJL != null) sheet1.Cells.Add(i + 3, 35, Source[i].GRJL.ToString(), xf);
                    if (Source[i].TC != null) sheet1.Cells.Add(i + 3, 36, Source[i].TC.ToString(), xf);
                    if (Source[i].SXZYKC != null) sheet1.Cells.Add(i + 3, 37, Source[i].SXZYKC.ToString(), xf);
                    if (Source[i].WY1 != null) sheet1.Cells.Add(i + 3, 38, Source[i].WY1.ToString(), xf);
                    if (Source[i].WY2 != null) sheet1.Cells.Add(i + 3, 39, Source[i].WY2.ToString(), xf);
                    if (Source[i].WYDJ1 != null) sheet1.Cells.Add(i + 3, 40, Source[i].WYDJ1.ToString(), xf);

                    if (Source[i].WYDJ2 != null) sheet1.Cells.Add(i + 3, 41, Source[i].WYDJ2.ToString(), xf);
                    if (Source[i].JSJSP != null) sheet1.Cells.Add(i + 3, 42, Source[i].JSJSP.ToString(), xf);
                    if (Source[i].TXDZ != null) sheet1.Cells.Add(i + 3, 43, Source[i].TXDZ.ToString(), xf);
                    if (Source[i].LXFS != null) sheet1.Cells.Add(i + 3, 44, Source[i].LXFS.ToString(), xf);
                    if (Source[i].SJHM != null) sheet1.Cells.Add(i + 3, 45, Source[i].SJHM.ToString(), xf);
                    if (Source[i].GZDW != null) sheet1.Cells.Add(i + 3, 46, Source[i].GZDW.ToString(), xf);
                    if (Source[i].GZNX != null) sheet1.Cells.Add(i + 3, 47, Source[i].GZNX.ToString(), xf);
                    if (Source[i].BYSJB != null) sheet1.Cells.Add(i + 3, 48, Source[i].BYSJB.ToString(), xf);
                    if (Source[i].SY != null) sheet1.Cells.Add(i + 3, 49, Source[i].SY.ToString(), xf);
                    if (Source[i].HJ != null) sheet1.Cells.Add(i + 3, 50, Source[i].HJ.ToString(), xf);

                    if (Source[i].YB != null) sheet1.Cells.Add(i + 3, 51, Source[i].YB.ToString(), xf);
                    if (Source[i].FangQiHuanJie != null) sheet1.Cells.Add(i + 3, 52, Source[i].FangQiHuanJie, xf);
                }
                xls.Save(ss);
                ss.Close();
                ss.Dispose();
                SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功！");

        }
    }
}
